package com.zrrd.sort;

import java.util.Arrays;

public class BucketSort {
    public void bucketSort(int[] array) {
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < array.length; i++) {
            max = array[i] > max ? array[i] : max;
        }
        int[] bucket = new int[max + 1];
        for (int tmp : array) {
            bucket[tmp]++;
        }
        int k = 0;
        for (int i = 0; i < bucket.length; i++) {
            for (int j = 0; j < bucket[i]; j++) {
                array[k++] = i;
            }
        }
    }

    public static void main(String[] args) {
        int[] array = new int[]{4, 2, 1, 0, 6, 7, 9, 8, 5};
        BucketSort bs = new BucketSort();
        bs.bucketSort(array);

        System.out.println(Arrays.toString(array));
    }
}

